package com.baosight.sczx.zm.cm.service;

import java.util.HashMap;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.zm.cm.domain.ZMCMStockPlanDetail;

public class ServiceZMCMJ2 extends ServiceEPBase 
{
	/**
	 * 
	 * <p>Function: initLoad</p>
	 * <p>Description: 初始化</p>
	 * <p>return value: ServiceZMCMJ2</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-12-12下午04:23:47 bobswang
	 * </p>
	 *
	 */
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cs.units"));//构造计量单位下拉框
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cm.org", "orgCode", "orgName", false));
		outInfo.addBlock(getMonth());
		
		return outInfo;
	}
	/**
	 * 
	 * <p>Function: query</p>
	 * <p>Description: 查询</p>
	 * <p>return value: ServiceZMCMJ2</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-12-12下午04:24:01 bobswang
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) 
	{
		EiInfo outInfo = super.query(inInfo, "ZMCMWholeQuery.queryStockPlan",new ZMCMStockPlanDetail());
		
		return outInfo;
	}
	
	/// <summary>
    /// 选取月份的block，包含空
    /// </summary>
    /// <param name="isAll"></param>
    /// <returns></returns>
    @SuppressWarnings({ "rawtypes", "unchecked" })
	public EiBlock getMonth()
    {
    	EiBlock block = new EiBlock("cmes.cm.month");

        EiColumn eiColumn = new EiColumn("value");
        eiColumn.setType("C");
		eiColumn.setFieldLength(3);
		block.addMeta(eiColumn);

        for (int i = 1; i < 13; i++)
        {
        	Map row = new HashMap();
            row.put("value", i);
    		block.addRow(row);
        }
        
        return block;
    }
}
